package util;

public class Util {

	public static int max(int[] array) {

		int max = 0;
		for (int index = 0; index < array.length; index++) {
			if (array[index] > max) {
				max = array[index];
			}
		}

		return max;
	}
	
	public static int min(int[] array) {

		int min = Integer.MAX_VALUE;
		for (int index = 0; index < array.length; index++) {
			if (array[index] < min) {
				min = array[index];
			}
		}

		return min;
	}
	
	public static int[] getMinArray( int[] array, int start, int end ){
		int[] newArray = new int[end-start];
		
		int lowest = min( array );
		
		/* Subtract lowest from every y */
		for( int iDim = start; iDim < end; iDim++ ){
			newArray[iDim] = array[iDim] - lowest;
		}
		
		return newArray;
	}
	
	public static int[] combine (int[] first, int[] second) {
		int[] totalEmptySpace = first.clone();
		for (int i = 0; i < totalEmptySpace.length; i++) {
			totalEmptySpace[i] += second[i];
		}
		return totalEmptySpace;
	}
	
	public static int[] intArrayFromString( String inputString, String seperator ){
		String[] splittedString = inputString.split( seperator );
		int[] intArray = new int[ splittedString.length ];
		
		try{
			for( int i=0; i < splittedString.length; i++ ){
				intArray[i] = Integer.parseInt( splittedString[i].trim() );
			}
		} catch( NumberFormatException e ){
			System.err.println( "input should be ints, dimwit!" );
		}
		
		return intArray;
	}
}
